package com.panpa.testeyes;

import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.View.*;
import android.view.*;
import java.util.*;
import android.util.*;
import android.content.*;
/**

MengTong 2020.2.29
一个花五分钟写的玩的测视力APP,
aide项目
各方面都比较简陋，代码也不够简洁
但是涉及一些取随机数，按钮点击事件等一些基础性的东西，
开源出来可以给那些想学Android和正在起步的人一些帮助
我也是萌新，大家一起学习。
**/
public class MainActivity extends Activity 
{
	private int point;
	private String b="0";
	
	 
	
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		final  ImageView ImageView=findViewById(R.id.mainImageView1);
		Button up=findViewById(R.id.mainButton1);
		Button Down=findViewById(R.id.mainButton3);
		Button left=findViewById(R.id.mainButton4);
		Button right=findViewById(R.id.mainButton2);
		//"E"的旋转角度集合
		final int[] i = {0,90,180,270};
		//取屏膜高和宽
		DisplayMetrics metrics = new DisplayMetrics();
		WindowManager manager = (WindowManager)MainActivity.this.getSystemService(Service.WINDOW_SERVICE);
		if (manager != null) {
			manager.getDefaultDisplay().getMetrics(metrics);
		}

		final int screenHeight = metrics.heightPixels; 
        int screenWidth = metrics.widthPixels;
		
		RelativeLayout.LayoutParams params= (RelativeLayout.LayoutParams) ImageView.getLayoutParams();
		params.height=screenHeight/3;
		params.width=screenWidth;
		ImageView.setLayoutParams(params);
		//谅我左右不分，上下左右点击事件绕了半天，所以有点乱
		up.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					
					
					RelativeLayout.LayoutParams params= (RelativeLayout.LayoutParams) ImageView.getLayoutParams();
					//取屏幕宽和高的二分之一
					params.height=params.height/2;
					params.width=params.width/2;
					ImageView.setLayoutParams(params);
					
					
					
					if(  ImageView.getRotation() == 270)
						{
							point=point+5;
						
							}
					if(params.height==screenHeight/192)//192是计算出来的
					{
						//intent跳转界面
						Intent intent=new Intent(MainActivity.this,over.class);
						intent.putExtra("get",""+point);
						startActivity(intent);
						finish();//跳转同时finish掉当前界面
					}
					//在集合中取随机数
					Random random = new Random();
					int r = random.nextInt(i.length);
					int a = i[r];
					b=String.valueOf(a);//int转string
					Float c=Float.valueOf(b);//string转float
					Log.i("随机数", "" + ImageView.getRotation());
					ImageView.setRotation(c);//设置图片旋转角度
					
					}
					
			});
		Down.setOnClickListener(new OnClickListener(){

				

				@Override
				public void onClick(View p1)
				
				
				{
					RelativeLayout.LayoutParams params= (RelativeLayout.LayoutParams) ImageView.getLayoutParams();
					params.height=params.height/2;
					params.width=params.width/2;
					ImageView.setLayoutParams(params);
					
					
					
					if(  ImageView.getRotation() == 90)
					{
						point=point+5;
						
					}
					if(params.height==screenHeight/192)
					{
						
						Intent intent=new Intent(MainActivity.this,over.class);
						intent.putExtra("get",""+point);
						startActivity(intent);
						finish();
					}
					Random random = new Random();
					int r = random.nextInt(i.length);
					int a = i[r];
					b=String.valueOf(a);
					Float c=Float.valueOf(b);
					Log.i("随机数", "" + ImageView.getRotation());
					ImageView.setRotation(c);
					}
			});
		right.setOnClickListener(new OnClickListener(){

				

				@Override
				public void onClick(View p1)
				{
					RelativeLayout.LayoutParams params= (RelativeLayout.LayoutParams) ImageView.getLayoutParams();
					params.height=params.height/2;
					params.width=params.width/2;
					ImageView.setLayoutParams(params);
					
					if(  ImageView.getRotation() == 0)
					{
						point=point+5;
						
					}
					if(params.height==screenHeight/192)
					{
						
						Intent intent=new Intent(MainActivity.this,over.class);
						intent.putExtra("get",""+point);
						startActivity(intent);
						finish();
					}
					
					Random random = new Random();
					int r = random.nextInt(i.length);
					int a = i[r];
					b=String.valueOf(a);
					Float c=Float.valueOf(b);
					Log.i("随机数", "" + ImageView.getRotation());
					ImageView.setRotation(c);
					
					
					}
			});
		left.setOnClickListener(new OnClickListener(){

				

				
				@Override
				public void onClick(View p1)
				{
					RelativeLayout.LayoutParams params= (RelativeLayout.LayoutParams) ImageView.getLayoutParams();
					params.height=params.height/2;
					params.width=params.width/2;
					ImageView.setLayoutParams(params);
					
					if(  ImageView.getRotation() == 180)
					{
						
						point=point+5;
						

					}
					if(params.height==screenHeight/192)
					{
						
						Intent intent=new Intent(MainActivity.this,over.class);
						intent.putExtra("get",""+point);
						startActivity(intent);
						finish();
					}
					Random random = new Random();
					int r = random.nextInt(i.length);
					int a = i[r];
					b=String.valueOf(a);
					Float c=Float.valueOf(b);
					Log.i("随机数", "" + ImageView.getRotation());
					ImageView.setRotation(c);
					
				}
			});
			
    }
}
